import request from '@/utils/request'
import { CategoryResponse, AttrResponse, AttrObj } from './type'

enum API {
  CATEGORY1_URL = '/admin/product/getCategory1',

  CATEGORY2_URL = '/admin/product/getCategory2/',

  CATEGORY3_URL = '/admin/product/getCategory3/',

  FIND_BASE_CATEGORY3_URL = '/admin/product/inner/findBaseCategory3ByCategory3IdList',

  ATTR_URL = '/admin/product/attrInfoList/',

  SAVE_ATTR_URL = '/admin/product/saveAttrInfo',

  DELETE_ATTR_URL = '/admin/product/deleteAttr/'
}

export const reqCategory1 = () =>
  request.get<any, CategoryResponse>(API.CATEGORY1_URL)
export const reqCategory2 = (category1Id: number) =>
  request.get<any, CategoryResponse>(API.CATEGORY2_URL + category1Id)
export const reqCategory3 = (category2Id: number) =>
  request.get<any, CategoryResponse>(API.CATEGORY3_URL + category2Id)
export const reqFindBaseCategory3 = (category3IdList: number[]) =>
  request.post<any, any>(API.FIND_BASE_CATEGORY3_URL, category3IdList)

export const reqAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, AttrResponse>(
    API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )

// 保存属性接口
export const reqSaveAttr = (attrInfo: AttrObj) =>
  request.post<any, any>(API.SAVE_ATTR_URL, attrInfo)



// 删除属性接口
export const reqDeleteAttr = (id: number) =>
  request.delete<any, any>(API.DELETE_ATTR_URL + id)